<template>
    <div class="app-container">
        <div class="contentBox">
            <div class="searchBox">
                <el-form :model="queryParams" ref="queryRef" :inline="true" @submit.prevent>
                    <el-form-item prop="name" style="margin: 0 6px 0 0;">
                        <el-input
                            class="inputBox"
                            v-model="queryParams.name"
                            placeholder="请输入名称"
                            clearable
                            @keyup.enter="handleQuery"
                        />
                    </el-form-item>
                    <el-form-item style="margin: 0 6px 0 0;">
                        <el-button class="normalFormBg searchBtn" icon="Search" @click="handleQuery"></el-button>
                        <el-button class="normalFormBg searchBtn" icon="Refresh" @click="resetQuery"></el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-row :gutter="10" style="margin: 16px 0;">
                <el-col :span="1.5">
                    <div class="normalBtn pageFlex pageFlexCenter" @click="handleAdd">
                        <img src="@/assets/images/plus.png" class="normalBtn_icon">
                        <div class="normalBtn_text">新增</div>
                    </div>
                </el-col>
            </el-row>
            <el-table 
                v-loading="loading"
                :data="dataList"
                border>
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column prop="date" label="日期" width="100" :show-overflow-tooltip="true" fixed="left"></el-table-column>
                <el-table-column prop="creditCode" label="物料编码" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="名称" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="货位号" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="规格" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="品牌型号" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="单位" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="入库数量" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="单价" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="总金额" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="入库人" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="入库凭证号" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="类别" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="供货商" width="150"></el-table-column>
		        <template #empty>
                    <el-empty description="暂无数据" style="color: var(--el-color-primary);"/>
                </template>
            </el-table>
            <div class="pageFlex pageAlignCenter pageSpaceBetween" style="margin-top: 20px;">
                <div class="totalText">共计 {{total}} 条</div>
                <el-pagination background layout="prev, pager, next" :total="total" :current-page="queryParams.pageNum" :page-size="queryParams.pageSize" @current-change="handleCurrentChange"/>
            </div>
        </div>
        <el-drawer v-model="modalShow" direction="rtl" size="838" :title="modalTitle">
            <div class="modalBox">
                <div class="modalBoxContent">
                    <el-form
                        ref="formRef"
                        class="formContent"
                        label-width="135"
                        :model="form"
                        :rules="rules"
                        :disabled="modalTitle === '价格配置详情'"
                    >
                        <div class="formContentTop pageFlex pageAlignCenter">
                            <div class="line"></div>
                            <div class="title">价格信息</div>
                        </div>
                        <div class="formContentCenter bgFF">
                            <el-form-item label="价格名称"></el-form-item>
                            <el-form-item label="结算月"></el-form-item>
                            <el-form-item label="结算日"></el-form-item>
                            <el-form-item label="备注"></el-form-item>
                            <el-table :data="form.dataList" border>
                                <el-table-column prop="id" label="" width="80" :show-overflow-tooltip="true"></el-table-column>
                                <el-table-column prop="floor" label="阶梯级数" width="120" :show-overflow-tooltip="true"></el-table-column>
                                <el-table-column label="起始值" width="180">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.start" style="width: 155px" placeholder="请输入起始值" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="结束值" width="180">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.stop" style="width: 155px" placeholder="请输入结束值" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="单位(元/立方米)" width="180">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.price" style="width: 155px" placeholder="请输入单位" />
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-form-item>
                                <template #label>
                                    <el-text style="color: var(--el-color-error);">?</el-text>
                                    <el-text>说明</el-text>
                                </template>
                                <el-text>(1)修改结算月和结算日会影响系统收费</el-text>
                                <el-text>(2)结算日只针对表端计费方式有效,即IC卡(除一表一卡)和远程预付费,系统计费结算日设定为1号,修改无效</el-text>
                                <el-text>(3)启用月阶梯时结算月无效,为每个月的结算日进行结算</el-text>
                            </el-form-item>
                        </div>
                        <div class="formContentTop pageFlex pageAlignCenter">
                            <div class="line"></div>
                            <div class="title">阶梯信息</div>
                        </div>
                        <div class="formContentCenter bgFF">
                            <el-form-item label="系统阶梯收费功能"></el-form-item>
                            <el-form-item label="阶梯计算周期"></el-form-item>
                            <el-form-item>
                                <template #label>
                                    <div class="pageFlex pageAlignCenter">
                                        <el-text>阶梯折算</el-text>
                                        <el-popover placement="left" :width="300">
                                            <template #reference>
                                                <el-icon style="color: var(--el-color-primary);cursor: pointer;"><QuestionFilled /></el-icon>
                                            </template>
                                            <template #default>
                                                <div>1）IC卡用户，在首次开户，结算周期不满一年时，系统会根据本周起的实际使用时间进行折算阶梯分界点。</div>
                                                <div>2）后付费和账户预存用户，抄表结算周期超过一年时，系统会根据本周期的实际使用时间进行折算阶梯分界点。</div>
                                                <div>注：天数不足一个月不折算</div>
                                            </template>
                                        </el-popover>
                                    </div>
                                </template>
                            </el-form-item>
                            <el-form-item label="按用户阶梯"></el-form-item>
                            <el-form-item label="结算年"></el-form-item>
                            <el-form-item>
                                <template #label>
                                    <div class="pageFlex pageAlignCenter">
                                        <el-text>计费周期</el-text>
                                        <el-popover placement="left" :width="160">
                                            <template #reference>
                                                <el-icon style="color: var(--el-color-primary);cursor: pointer;"><QuestionFilled /></el-icon>
                                            </template>
                                            <template #default>
                                                <div>单位:月</div>
                                                <div>建议不要超过36个月</div>
                                            </template>
                                        </el-popover>
                                    </div>
                                </template>
                            </el-form-item>
                            <el-form-item label="分界点选择"></el-form-item>
                            <el-form-item label="阶梯收费方式选择"></el-form-item>
                            <el-form-item>
                                <template #label>
                                    <div class="pageFlex pageAlignCenter">
                                        <el-text>最低人口数P</el-text>
                                        <el-popover placement="left" :width="160">
                                            <template #reference>
                                                <el-icon style="color: var(--el-color-primary);cursor: pointer;"><QuestionFilled /></el-icon>
                                            </template>
                                            <template #default>
                                                <div>小于等于最低人数时按默认分界点，超过时分界点将递增</div>
                                            </template>
                                        </el-popover>
                                    </div>
                                </template>
                            </el-form-item>
                            <el-form-item>
                                <template #label>
                                    <div class="pageFlex pageAlignCenter">
                                        <el-text>超出人口数增量N</el-text>
                                        <el-popover placement="left" :width="160">
                                            <template #reference>
                                                <el-icon style="color: var(--el-color-primary);cursor: pointer;"><QuestionFilled /></el-icon>
                                            </template>
                                            <template #default>
                                                <div>超过最低人数时，每增加一人，分界点增加多少量</div>
                                            </template>
                                        </el-popover>
                                    </div>
                                </template>
                            </el-form-item>
                            <el-form-item>
                                <template #label>
                                    <div class="pageFlex pageAlignCenter">
                                        <el-text>系数</el-text>
                                        <el-popover placement="left" :width="160">
                                            <template #reference>
                                                <el-icon style="color: var(--el-color-primary);cursor: pointer;"><QuestionFilled /></el-icon>
                                            </template>
                                            <template #default>
                                                <div>分界点等于系数乘以面积</div>
                                            </template>
                                        </el-popover>
                                    </div>
                                </template>
                            </el-form-item>
                            <el-form-item>
                                <template #label>
                                    <el-text style="color: var(--el-color-error);">?</el-text>
                                    <el-text>说明</el-text>
                                </template>
                                <el-text>价格创建后，可使用操作列的发布功能，将价格下发至表具</el-text>
                                <el-text>(1)若存在预调价格且执行日期小于等于当天，发布后优先将预调价格更新到当前价格。</el-text>
                                <el-text>(2)发布后系统会生成设置价格任务，并自动下发至表具</el-text>
                                <el-text>(3)若使用有第三方厂家的表具，发布后系统会自动调用第三方下发价格接口</el-text>
                            </el-form-item>
                        </div>
                    </el-form>
                </div>
                <div class="lineBox" v-if="modalTitle !== '价格配置详情'"></div>
                <div class="bottomBox pageFlex pageFlexCenter" v-if="modalTitle !== '价格配置详情'">
                <el-button type="primary" :loading="submitLoading" @click="submitNow">确认提交</el-button>
                </div>
                <el-button type="primary" :loading="formLoading" class="modalLoadingBox" v-if="formLoading">加载数据中</el-button>
            </div>
        </el-drawer>
    </div>
</template>
<script setup>
import { onMounted } from 'vue';
import { searchPriceInfoApi, addPriceInfoApi, searchPriceInfoByIdApi, editPriceInfoApi, deletePriceInfoApi } from '@/api/gasManage/defaultSetting/priceInfo';
const { proxy } = getCurrentInstance();
// -------------------------------------弹窗-------------------------------------
const modalShow = ref(false);
const modalTitle = ref('');
const submitLoading = ref(false);
const formLoading = ref(false);
const form = ref({
    dataList: [
        { id: 1, floor: '阶梯一档', start: 0, stop: 0, price: 2.74},
        { id: 2, floor: '阶梯二档', start: 0, stop: 0, price: 2.74},
        { id: 3, floor: '阶梯三档', start: 0, stop: 99999, price: 2.74}
    ]
});
const rules = ref({});
function handleModalShow(name){
    modalShow.value = true;
    modalTitle.value = name
}
function submitNow(){

}
// -------------------------------------新增-------------------------------------
function handleAdd(){
    handleModalShow('新增价格配置');
}
// -------------------------------------查询-------------------------------------
onMounted(()=>{
    getList();
})
const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
    name: ''
})
const loading = ref(false);
const total = ref(0);
const dataList = ref([]);
function handleQuery(){
    queryParams.value.pageNum = 1;
    getList();
}
function resetQuery(){
    proxy.resetForm("queryRef");
    handleQuery();
}
async function getList(){
  loading.value = true;
  let data = await getPriceInfoList(queryParams.value);
  if(data && Array.isArray(data)){
    dataList.value = data;
  }else{
    dataList.value = [];
  }
  loading.value = false;
}
function getPriceInfoList(params){
  return new Promise(resolve => {
    searchPriceInfoApi(params).then(res => {
      total.value = Number(res.total);
      resolve(Array.isArray(res.rows) ? res.rows : []);
    }).catch(() => {resolve(false)})
  })
}
function handleCurrentChange(e){
  queryParams.value.pageNum = e;
  getList();
}
</script>
<style lang='scss' scoped>
@import "@/assets/styles/public.scss";
:deep(.el-input){
    .el-input__wrapper{
        background-color: $formBgSet;
        box-shadow: none;
    }
}
.app-container{
    width: 100%;
    min-height: calc(100vh - 66px);
    background: #F8F8F9;
    .contentBox{
        width: 100%;
        min-height: calc(100vh - $navBarHeight - 40px);
        background-color: #FFFFFF;
        border-radius: 5px;
        box-sizing: border-box;
        padding: 12px;
        .searchBtn{
            width: 32px;
            height: 32px;
            font-size: 12px;
            padding: 0;
            border: none;
            margin: 0 6px 0 0px;
        }
        .btnSetBox{
            padding: 0 10px;
            box-sizing: border-box;
            border-right: 1px solid $borderColor;
            cursor: pointer;
            .text{
                height: 16px;
                line-height: 16px;
                color: var(--el-color-primary);
            }
            .img{
                width: 16px;
                height: 16px;
                margin-right: 2px;
            }
            &:last-child{
                border-right: none;
            }
        }
        .totalText{
            height: 22px;
            font-weight: 400;
            font-size: 14px;
            color: #1D2129;
            line-height: 22px;
        }
    }
}
:deep(.el-drawer){
  .el-drawer__header{
    margin: 0;
    padding-bottom: 20px;
  }
  .el-drawer__body{
    padding: 0;
  }
}
</style>

